Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bandwidth: use regexp to handle tc output and add IPv6 support #83572

Merged
merged 1 commit into from
Mar 4, 2020

Conversation

chendotjs
Copy link
Contributor

@chendotjs chendotjs commented Oct 7, 2019

What type of PR is this?
/kind bug

What this PR does / why we need it:

  1. fix newly-added 'chain N' and 'not_in_hw' output from 'tc filter show dev XXX'
  2. use regexp to extract info we want from tc output, instead of splitting the output line

Which issue(s) this PR fixes:

Fixes #76064

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix a bug where kubenet fails to parse the tc output. 

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 7, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @chendotjs. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added sig/network Categorizes an issue or PR as relevant to SIG Network. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 7, 2019
@chendotjs
Copy link
Contributor Author

/assign @dcbw @danwinship

Copy link
Contributor

@danwinship danwinship left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely like the idea

// expected tc line:
// class htb 1:1 root prio 0 rate 1000Kbit ceil 1000Kbit burst 1600b cburst 1600b
if len(parts) != 14 {
return -1, fmt.Errorf("unexpected output from tc: %s (%v)", scanner.Text(), parts)
classShowMatcher := regexp.MustCompile(`class\shtb\s(1:\d+)\sroot.*rate\s`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you matching the "root.*rate" part too? Does that avoid some false positive? (If so maybe update the comment to indicate the kind of line you're trying to avoid matching too.)
Also, I'm not sure that using "\s" rather than just " " makes this any more generic/future-proof, and it makes it harder to read... (That applies throughout the patch.)
Also, you could make all of the MustCompile regexes be top-level variables so they only get compiled once rather than getting recompiled every time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code uses command like tc class add dev xxx parent 1: classid 1:x htb rate 1kbit to add a new class where rate is an explicit parameter, so "root.*rate" ought to be matched explicitly. This is my primitive idea.
Other advice really make sense, thanks

// expected tc line:
// match <cidr> at <number>
if len(parts) != 4 {
return nil, fmt.Errorf("unexpected output: %v", parts)
cidrMatcher := regexp.MustCompile(`match\s([0-9a-f]{8}\/[[0-9a-f]{8}).*\s(\d+)`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is really an improvement over the old code. Also, it only handles IPv4 (the two hex strings are {32}, not {8} for IPv6; perhaps the test case should be updated for that). Also, there's no need to put ()s around the \d+ since you're not using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently IPv6 is not yet supported I suppose? Because the code uses command like tc filter add dev xxx protocol ip parent 1:0 prio 1 u32 match ip dst 1.2.3.4/32 flowid 1:2, the SELECTOR after match is ip, not ip6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... TestHexCIDR and TestAsciiCIDR test IPv6 addresses and the old code would have matched either IPv4 or IPv6 so I assumed we cared. If not then I guess someone will fix this when they add IPv6 support here. (Although I don't know if anyone realized that the bandwidth code doesn't currently support IPv6. @khenidak do you know if this is being tracked?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure that IPv6 is not supported currently and I'll fix it.

@chendotjs chendotjs force-pushed the tc-fix branch 2 times, most recently from 7e204f5 to 1749e71 Compare October 7, 2019 16:34
@alejandrox1
Copy link
Contributor

alejandrox1 commented Oct 7, 2019

/ok-to-test
/milestone v1.17
/priority important-soon

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 7, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.17 milestone Oct 7, 2019
@k8s-ci-robot k8s-ci-robot added priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 7, 2019
@alejandrox1
Copy link
Contributor

/remove-priority critical-urgent

@k8s-ci-robot k8s-ci-robot removed the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Oct 7, 2019
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 21, 2019
@markjacksonfishing
Copy link

@MrHohn @freehan @chendotjs We are fast approaching code freeze on 11/14. Hopefully we can get this in 1.17?

@markjacksonfishing
Copy link

Circling back on this @chendotjs @MrHohn @freehan, code freeze is 11/14 and by 5 pm pst I need to make the call if this gets moved out of this milestone.

@markjacksonfishing
Copy link

I have had no response to this and code freeze is tomorrow. I have to move this to milestone v1.18

@markjacksonfishing
Copy link

/milestone v1.18

@k8s-ci-robot k8s-ci-robot modified the milestones: v1.17, v1.18 Nov 13, 2019
@dcbw
Copy link
Member

dcbw commented Jan 9, 2020

@chendotjs can you rebase to fix the conflict? thanks!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 10, 2020
@chendotjs
Copy link
Contributor Author

@dcbw commits have been rebased and squashed.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jan 14, 2020
@jtslear
Copy link

jtslear commented Feb 12, 2020

Hello @danwinship and @dcbw,
Bug Triage team here for the 1.18 release. This is a friendly reminder that code freeze is scheduled for 5 March. Is this PR still intended for milestone 1.18?

@jtslear
Copy link

jtslear commented Feb 28, 2020

Hello @danwinship and @dcbw,
Bug Triage team here for the 1.18 release. This is a friendly reminder that code freeze is scheduled for 5 March. We are waiting review on this PR, there's been no movement on this since mid January.

cc @kubernetes/sig-network-pr-reviews

@danwinship
Copy link
Contributor

The IPv6 support here seems extremely complicated and I feel like it ought to be possible to simplify it a lot.

I would recommend just reverting back to the original version of the PR, addressing the non-IPv6-related comments, and resubmitting that, and then we can think about IPv6 support again later.

fix newly-added 'chain N' output from 'tc filter show dev XXX'
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 3, 2020
@chendotjs
Copy link
Contributor Author

Truly thanks for your practical advice ! @danwinship
This pr has been reverted and follows the non-IPv6-related comments, ptal if you have time.

@danwinship
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chendotjs, danwinship

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2020
@cadmuxe
Copy link
Member

cadmuxe commented Mar 4, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit e4e3d72 into kubernetes:master Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubelet Bandwidth Limiting Not Working